package org.parademo.jess;

import jess.Activation;
import jess.Strategy;

import java.io.Serializable;

/**
 * This class is a simple implementation for a conflict resolution strategy between applicable rules
 * by comparing their salience values set.
 *
 * @author Ajit Skanda
 * @version 1.0
 * @see {@link jess.Strategy}
 */

public class SimpleRuleConflictResolutionStrategy implements Strategy, Serializable {

    private static final String STRATEGY_NAME = "SimpleRuleConflictResolutionStrategy";

    public SimpleRuleConflictResolutionStrategy() {
    }

    public int compare(Activation act1, Activation act2) {
        int result;
        int salience1 = act1.getSalience();
        int salience2 = act2.getSalience();

        if (salience1 < salience2) {
            result = 1;
        } else if (salience1 > salience2) {
            result = -1;
        } else {
            result = 0;
        }

        return result;
    }

    public String getName() {
        return STRATEGY_NAME;
    }
}
